"""
检查系统可用的中文字体
"""
import matplotlib.font_manager as fm

print("=" * 70)
print("系统中可用的中文字体：")
print("=" * 70)

# 获取所有字体
fonts = fm.findSystemFonts(fontpaths=None, fontext='ttf')

# 查找可能的中文字体
chinese_fonts = []
font_names = set()

for font_path in fonts:
    try:
        font_prop = fm.FontProperties(fname=font_path)
        font_name = font_prop.get_name()
        
        # 查找常见的中文字体
        if any(keyword in font_name.lower() for keyword in 
               ['hei', 'song', 'kai', 'fang', 'chinese', 'sim', 'microsoft', 
                'pingfang', 'hiragino', 'stxihei', 'stheiti', 'stkaiti', 
                'stsong', 'stfangsong', 'arial unicode']):
            if font_name not in font_names:
                font_names.add(font_name)
                chinese_fonts.append((font_name, font_path))
    except:
        pass

# 排序并显示
chinese_fonts.sort()
for i, (name, path) in enumerate(chinese_fonts, 1):
    print(f"{i:2d}. {name}")
    if i <= 5:  # 只显示前5个的路径
        print(f"    路径: {path}")

print("\n" + "=" * 70)
print("推荐配置（按优先级）：")
print("=" * 70)

# 推荐的字体配置
recommended = []
for name, _ in chinese_fonts:
    name_lower = name.lower()
    if 'pingfang' in name_lower or 'hiragino' in name_lower:
        recommended.insert(0, name)  # macOS 字体优先
    elif 'simhei' in name_lower or 'stheiti' in name_lower:
        recommended.append(name)
    elif 'arial unicode' in name_lower:
        recommended.append(name)

if recommended:
    print("\n建议使用以下配置：")
    print("plt.rcParams['font.sans-serif'] = " + str(recommended[:3]))
else:
    print("\n未找到常见中文字体，尝试使用系统默认配置")

print("\n" + "=" * 70)
